local skel = fk.CreateSkill {
  name = "efengqi__jizhan",
}

Fk:loadTranslationTable{
  ["efengqi__jizhan"] = "急斩",
  [":efengqi__jizhan"] = "你的回合外，当其他角色于一回合内每发动六次技能后，你可以视为对其使用了一张不可响应的【杀】；若其未受伤，此【杀】伤害基数+1。游戏开始时，你可以令“急斩”变为锁定技，若如此做，其他角色每获得一牌时“急斩”计数+1。",

  ["@efengqi__jizhan-turn"] = "急斩",
  ["#efengqi__jizhan-invoke"] = "急斩: 现在你可以视为对 %dest 使用基础伤害为 %arg 的【杀】",
  ["#efengqi__jizhan-crazy"] = "你可以将“急斩”改为锁定技，若如此做，其他角色摸牌时“急斩”计数+1。",

  ["$efengqi__jizhan"] = "纳命来！",
}

skel:addEffect(fk.AfterSkillEffect, {
  anim_type = "offensive",
  can_trigger = function(self, _, target, player, data)
    local slash = Fk:cloneCard ("slash")
    slash.skillName = skel.name
    return player:hasSkill(skel.name) and player.phase == Player.NotActive and
      target and target ~= player and
      (data.extra_data or Util.DummyTable).efengqi__jizhan and
      not player:prohibitUse(slash) and
      not player:isProhibited(target, slash)
  end,
  on_cost = function(self, event, target, player, data)
     return player.room:getBanner("crazy_jizhan") or
     player.room:askToSkillInvoke(player, {
      skill_name = skel.name,
      data = data,
      prompt = "#efengqi__jizhan-invoke::"..target.id..":"..(target:isWounded() and 1 or 2)
    })
  end,
  on_use = function(self, _, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard ("slash")
    slash.skillName = skel.name
    room:useCard {
      from = player,
      tos = { target },
      card = slash,
      additionalDamage = target:isWounded() and 0 or 1,
      disresponsiveList = table.simpleClone(room.players),
    }
  end,
})

skel:addEffect(fk.AfterSkillEffect, {
  can_refresh = function(self, _, target, player, data)
    return target == player and
      table.contains(target:getSkillNameList(), data.skill:getSkeleton().name) and not data.skill.is_delay_effect and
      table.find(player.room.alive_players, function (p)
        return p:hasSkill(skel.name) and p.phase == Player.NotActive and p ~= player
      end)
  end,
  on_refresh = function (self, _, target, _, data)
    local room = target.room
    room:addPlayerMark(target, "@efengqi__jizhan-turn", 1)
    if (target:getMark("@efengqi__jizhan-turn") % 6 == 0) then
      data.extra_data = data.extra_data or {}
      data.extra_data.efengqi__jizhan = true
    end
  end,
})

skel:addEffect(fk.GameStart, {
  anim_type = "offensive",
  can_trigger = function(self, _, target, player, data)
    return player:hasSkill(skel.name) and player.room:getBanner("crazy_jizhan") == nil
  end,
  on_cost = function(self, event, target, player, data)
     return player.room:askToSkillInvoke(player,{
      skill_name = skel.name,
      prompt = "#efengqi__jizhan-crazy"
    })
  end,
  on_use = function(self, _, target, player, data)
    player.room:setBanner("crazy_jizhan", true)
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  mute = true,
  can_trigger = function(self, _, target, player, data)
    if not player.dead and player.room:getBanner("crazy_jizhan") and
     table.find(player.room.alive_players, function (p)
      return p:hasSkill(skel.name) and p.phase == Player.NotActive and p ~= player
    end) then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Player.Hand then
          if #move.moveInfo > 0 then
            return true
          end
        end
      end
    end
  end,
  trigger_times = function (self, event, target, player, data)
    local n = 0
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Player.Hand then
        n = n + #move.moveInfo
      end
    end
    return n
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, _)
    local room = player.room
    room:addPlayerMark(player, "@efengqi__jizhan-turn", 1)
    if (player:getMark("@efengqi__jizhan-turn") % 6 == 0) then
      local skill = room.logic:getCurrentEvent():findParent(GameEvent.SkillEffect, true)
      if skill == nil then return end
      local data = skill.data
      data.extra_data = data.extra_data or {}
      data.extra_data.efengqi__jizhan = true
    end
  end,
})

return skel
